package com.xiaoxin.controller;

import com.xiaoxin.model.vo.PageResult;
import com.xiaoxin.model.vo.UserInfoVo;
import com.xiaoxin.service.AnnouncementService;
import com.xiaoxin.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author xiaoxiaode
 * @date 2021-09-07-20:43
 **/

@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @Autowired
    private AnnouncementService announcementService;

    /*
    * 根据环信用户id,查询用户详情
    * */
    @GetMapping("/userinfo")
    public ResponseEntity findByHuanXin(String huanxinId){
        UserInfoVo info=messageService.findByHuanXin(huanxinId);
        return ResponseEntity.ok(info);
    }

    /*
    * 添加联系人
    * */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        String id = map.get("userId").toString();
        Long friendId = Long.valueOf(id);
        messageService.contacts(friendId);
        return ResponseEntity.ok(null);
    }

    /*
    * 联系人列表
    * */
    @GetMapping("/contacts")
    public ResponseEntity contactFriends(@RequestParam(defaultValue = "1")Integer page,
                                         @RequestParam(defaultValue = "10")Integer pagesize,
                                         String keyword){
        PageResult pageResult=messageService.contactFriends(page,pagesize,keyword);
        return ResponseEntity.ok(pageResult);
    }

    /*
    * 点赞人列表
    * */
    @GetMapping("/likes")
    public ResponseEntity likes(@RequestParam(defaultValue = "1")Integer page,
                                @RequestParam(defaultValue = "10")Integer pagesize){
        PageResult pageResult=messageService.likes(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /*
    * 喜欢我的人列表
    * */
    @GetMapping("/loves")
    public ResponseEntity loves(@RequestParam(defaultValue = "1")Integer page,
                                @RequestParam(defaultValue = "10")Integer pagesize){
        PageResult pageResult=messageService.loves(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /*
    * 评论我的人列表
    * */
    @GetMapping("/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1")Integer page,
                                @RequestParam(defaultValue = "10")Integer pagesize){
        PageResult pageResult=messageService.comments(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /*
    * 公告
    * */
    @GetMapping("/announcements")
    public ResponseEntity announcements(@RequestParam(defaultValue = "1")Integer page,
                                   @RequestParam(defaultValue = "10")Integer pagesize){
        PageResult pageResult=announcementService.announcements(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
}
